/**
 *  @(#)  IFAAAuthenticator  module    1.0  2017/03/24
 *
 *  Copyright  (c)  2017,  IFAA  and/or  its  affiliates.  All  rights  reserved.
 *
 *  Redistribution  and  use  in  source  and  binary  forms,  with  or  without
 *  modification,  are  permitted  provided  that  the  following  conditions  are  met:
 *
 *  -Redistribution  of  source  code  must  retain  the  above  copyright  notice,  this
 *    list  of  conditions  and  the  following  disclaimer.
 *
 *  -Redistribution  in  binary  form  must  reproduce  the  above  copyright  notice,
 *    this  list  of  conditions  and  the  following  disclaimer  in  the  documentation
 *    and/or  other  materials  provided  with  the  distribution.
 *
 *  Neither  the  name  of  IFAA  or  the  names  of  contributors  may
 *  be  used  to  endorse  or  promote  products  derived  from  this  software  without
 *  specific  prior  written  permission.
 *
 *  This  software  is  provided  "AS  IS,"  without  a  warranty  of  any  kind.  ALL
 *  EXPRESS  OR  IMPLIED  CONDITIONS,  REPRESENTATIONS  AND  WARRANTIES,  INCLUDING
 *  ANY  IMPLIED  WARRANTY  OF  MERCHANTABILITY,  FITNESS  FOR  A  PARTICULAR  PURPOSE
 *  OR  NON-INFRINGEMENT,  ARE  HEREBY  EXCLUDED.  IFAA,  ORG.
 *  AND  ITS  LICENSORS  SHALL  NOT  BE  LIABLE  FOR  ANY  DAMAGES  SUFFERED  BY  LICENSEE
 *  AS  A  RESULT  OF  USING,  MODIFYING  OR  DISTRIBUTING  THIS  SOFTWARE  OR  ITS
 *  DERIVATIVES.  IN  NO  EVENT  WILL  IFAA  OR  ITS  LICENSORS  BE  LIABLE  FOR  ANY  LOST
 *  REVENUE,  PROFIT  OR  DATA,  OR  FOR  DIRECT,  INDIRECT,  SPECIAL,  CONSEQUENTIAL,
 *  INCIDENTAL  OR  PUNITIVE  DAMAGES,  HOWEVER  CAUSED  AND  REGARDLESS  OF  THE  THEORY
 *  OF  LIABILITY,  ARISING  OUT  OF  THE  USE  OF  OR  INABILITY  TO  USE  THIS  SOFTWARE,
 *  EVEN  IF  IFAA  HAS  BEEN  ADVISED  OF  THE  POSSIBILITY  OF  SUCH  DAMAGES.
 *
 *  You  acknowledge  that  this  software  is  not  designed,  licensed  or  intended
 *  for  use  in  the  design,  construction,  operation  or  maintenance  of  any
 *  nuclear  facility.
 *
 */
package com.ifaa.sdk.auth.message;

import java.util.List;

/**
 * 
 * @author junsui.ljs
 * @version $Id: FingerPrintResponse.java, v 0.1 2014 5:14:22 junsui.ljs Exp $
 */
public class AuthenticatorResponse extends AuthenticatorMessage {

    /**
     * The operation completed successfully and the response message should be
     * send to the relying party's backend to be processed by MFAS
     */
    public static final int RESULT_SUCCESS                    = 100;

    /**
     * The operation failed for some nonspecific reson
     */
    public static final int RESULT_FAILURE                    = 101;
    /**
     * The operation was canceled by user
     */
    public static final int RESULT_CANCELED                   = 102;
    /**
     * No matching authentication method is found to process the request
     */
    public static final int RESULT_NO_MATCH                   = 103;
    /**
     * The origin URL does not match the server URL, and it is not found in the
     * manifest at the relying part
     */
    public static final int RESULT_INCORRECT_ORIGIN           = 104;

    /**
     * MFAC is not installed
     */
    public static final int RESULT_NOT_INSTALLED              = 105;

    /**
     * The installed version of MFAC is not compatible
     */
    public static final int RESULT_NOT_COMPATIBLE             = 106;

    /**
     * This application is not listed in the manifest at the relying party
     */
    public static final int RESULT_APP_NOT_FOUND              = 107;

    /**
     * The update transaction button was pressed
     */
    public static final int RESULT_UPDATE                     = 108;

    /**
     * The transaction text could not be processed, eg. certain HTML tag are not
     * allowed
     */
    public static final int RESULT_TRANSACTION_ERROR          = 109;

    /**
     * TSI Block cannot be verified
     */
    public static final int RESULT_TSI_ERROR                  = 110;

    /**
     * Mobile phone not support finger print
     */
    public static final int RESULT_NOT_SUPPORT                = 111;

    /**
     * Mobile phone did not resisted any finger print
     */
    public static final int RESULT_NOT_REGISTERED_FINGERPRINT = 112;

    /**
     * 超时
     */
    public static final int RESULT_TIMEOUT                    = 113;

    /**
     * 模板为空，未录入指纹
     */
    public static final int RESULT_NOT_ENROLLED               = 114;           //

    /**
     * 指纹未开启
     */
    public static final int RESULT_NOT_ENABLED                = 115;           //指纹功能未开启

    /**
     * 底层Sensor出错
     */
    public static final int RESULT_SENSOR_ERROR               = 116;           //底层或Sensor出错

    /**
     * 用户未开通指纹
     */
    public static final int RESULT_USER_NOTREGISTER           = 117;

    /**
     * 指纹服务被占用
     */
    public static final int RESULT_FINGERPRINT_BUSY           = 118;

    /**
     * 用户开通的指纹被删除
     */
    public static final int RESULT_REGISTERFINGER_DELETE      = 119;

    /**
     * 硬件错误
     */
    public static final int RESULT_HARDWARE_ERROR             = 120;

    /**
     * 切换密码输入
     */
    public static final int RESULT_CHANGE_TO_PASSWORD         = 121;

    /**
     * 指纹服务工作正常
     */
    public static final int RESULT_AUTHSERVICE_OK             = 122;

    /**
     * 蓝牙没有开启
     */
    public static final int RESULT_BLUETOOTH_OFF              = 123;

    /**
     * 设备被root
     */
    public static final int RESULT_ROOT                       = 124;

    /**
     * 蓝牙地址缺失
     */
    public static final int RESULT_NO_BLUETOOTH_MAC           = 125;

    /**
     * Service无法启动
     */
    public static final int RESULT_SERVICE_START_ERROR        = 126;

    /**
     * Service是旧版
     */
    public static final int RESULT_SERVICE_OLD                = 127;

    /**
     * 设备蓝牙类型未知
     */
    public static final int RESULT_DEVICE_TYPE_UNKNOWN        = 128;
    
    /**
     * 连续多次校验失败，指纹校验被暂时锁定
     */
    public static final int RESULT_SYSTEMBLOCK                = 129;

    /**
     * 服务被禁用
     */
    public static final int RESULT_SERVICE_DISABLED           = 130;

    /**
     * 设备销售地不支持
     */
    public static final int RESULT_DEVICE_NOT_SUPPORT_AREA    = 131;

    /**
     * 在支持指纹机型列表,rom版本旧导致不支持指纹支付
     */
    public static final int RESULT_NOT_SUPPORT_ROM_OLDER      = 132;

    /**
     * 在支持指纹机型列表,rom版本新导致不支持指纹支付
     */
    public static final int RESULT_NOT_SUPPORT_ROM_NEWER      = 133;

    /**
     * Permission Deny
     */
    public static final int RESULT_PERMISSION_DENY            = 403;

    /**
     * 打开指纹校验失败
     */
    public static final int RESULT_OPEN_VENDOR_FP_AUTH_FAILED = 404;

    /**
     * TEE调用返回空
     */
    public static final int RESULT_TEE_INVOKE_RETURN_NULL = 405;
    /**
     * version of the message
     */
    protected int           result                            = RESULT_SUCCESS;
    protected String        resultMessage;
    protected String        errorMessage;
    protected List<String>  resgistedTokens;

    public List<String> getResgistedTokens() {
        return resgistedTokens;
    }

    public void setResgistedTokens(List<String> resgistedTokens) {
        this.resgistedTokens = resgistedTokens;
    }

    public void setResultMessage(String resultMessage) {
        this.resultMessage = resultMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    /**
     * Constructor
     */
    public AuthenticatorResponse() {
        super();
    }

    /**
     * Constructor
     * @param type
     * @param version
     * @param data
     */
    public AuthenticatorResponse(int type, int version, String data) {
        super(type, version, data);
    }

    /**
     * Constructor
     * @param type
     * @param version
     */
    public AuthenticatorResponse(int type, int version) {
        super(type, version);
    }

    /**
     * Setter method for property <tt>result</tt>.
     * 
     * @param result value to be assigned to property result
     */
    public void setResult(int result) {
        this.result = result;
    }

    /**
     * Getter method for property <tt>result</tt>.
     * 
     * @return property value of result
     */
    public int getResult() {
        return result;
    }

    public String getResultMessage() {
        return resultMessage;
    }
    public static String  toString(int result) {
        switch (result) {
            case RESULT_SUCCESS:
                return "RESULT_SUCCESS";
            case RESULT_FAILURE:
                return "RESULT_FAILURE";
            case RESULT_CANCELED:
                return "RESULT_CANCELED";
            case RESULT_NO_MATCH:
                return "RESULT_NO_MATCH";
            case RESULT_INCORRECT_ORIGIN:
                return "RESULT_INCORRECT_ORIGIN";
            case RESULT_NOT_INSTALLED:
                return "RESULT_NOT_INSTALLED";
            case RESULT_NOT_COMPATIBLE:
                return "RESULT_NOT_COMPATIBLE";
            case RESULT_APP_NOT_FOUND:
                return "RESULT_APP_NOT_FOUND";
            case RESULT_UPDATE:
                return "RESULT_UPDATE";
            case RESULT_TRANSACTION_ERROR:
                return "RESULT_TRANSACTION_ERROR";
            case RESULT_TSI_ERROR:
                return "RESULT_TSI_ERROR";
            case RESULT_NOT_SUPPORT:
                return "RESULT_NOT_SUPPORT";
            case RESULT_NOT_REGISTERED_FINGERPRINT:
                return "RESULT_NOT_REGISTERED_FINGERPRINT";
            case RESULT_TIMEOUT:
                return "RESULT_TIMEOUT";
            case RESULT_NOT_ENROLLED:
                return "RESULT_NOT_ENROLLED";
            case RESULT_NOT_ENABLED:
                return "RESULT_NOT_ENABLED";
            case RESULT_SENSOR_ERROR:
                return "RESULT_SENSOR_ERROR";
            case RESULT_USER_NOTREGISTER:
                return "RESULT_USER_NOTREGISTER";
            case RESULT_FINGERPRINT_BUSY:
                return "RESULT_FINGERPRINT_BUSY";
            case RESULT_REGISTERFINGER_DELETE:
                return "RESULT_REGISTERFINGER_DELETE";
            case RESULT_HARDWARE_ERROR:
                return "RESULT_HARDWARE_ERROR";
            case RESULT_CHANGE_TO_PASSWORD:
                return "RESULT_CHANGE_TO_PASSWORD";
            case RESULT_AUTHSERVICE_OK:
                return "RESULT_AUTHSERVICE_OK";
            case RESULT_BLUETOOTH_OFF:
                return "RESULT_BLUETOOTH_OFF";
            case RESULT_ROOT:
                return "RESULT_ROOT";
            case RESULT_NO_BLUETOOTH_MAC:
                return "RESULT_NO_BLUETOOTH_MAC";
            case RESULT_SERVICE_START_ERROR:
                return "RESULT_SERVICE_START_ERROR";
            case RESULT_SERVICE_OLD:
                return "RESULT_SERVICE_OLD";
            case RESULT_DEVICE_TYPE_UNKNOWN:
                return "RESULT_DEVICE_TYPE_UNKNOWN";
            case RESULT_SYSTEMBLOCK:
                return "RESULT_SYSTEMBLOCK";
            case RESULT_SERVICE_DISABLED:
                return "RESULT_SERVICE_DISABLED";
            case RESULT_DEVICE_NOT_SUPPORT_AREA:
                return "RESULT_DEVICE_NOT_SUPPORT_AREA";
            case RESULT_NOT_SUPPORT_ROM_OLDER:
                return "RESULT_NOT_SUPPORT_ROM_OLDER";
            case RESULT_NOT_SUPPORT_ROM_NEWER:
                return "RESULT_NOT_SUPPORT_ROM_NEWER";
            case RESULT_PERMISSION_DENY:
                return "RESULT_PERMISSION_DENY";
            case RESULT_OPEN_VENDOR_FP_AUTH_FAILED:
                return "RESULT_OPEN_VENDOR_FP_AUTH_FAILED";
            case RESULT_TEE_INVOKE_RETURN_NULL:
                return "RESULT_TEE_INVOKE_RETURN_NULL";
            default:
                return String.valueOf(result);
        }
    }
}
